#include <stdio.h>

int compare(char a[], char b[])
{
	int i=1;
	while(1)
	{
		if(a[i]>b[i])
		{
			return 1;
		}
		if(b[i]>a[i])
		{
			return 2;
		}
		i++;
	}
}




int main()
{
	char sentence[81];
	int pl_s = 1;

	while(1)
	{
		scanf("%c",&sentence[pl_s]);
		if(sentence[pl_s] == '.' || sentence[pl_s] == '?' || sentence[pl_s] == '!')
			break;
		pl_s ++;
	} 
	char words[21][21];
	
	for(int i=1;i<=20;i++)
	{
		for(int j=1;j<=20;j++)
		{
			words[i][j]='\0';
		}
	} 
	 
	int tmp_n1=1,tmp_n2=1;
	int pl_w=1;
	int lenth_w[21];
	
	lenth_w[tmp_n1] = 0;
	
	while(1)
	{
		if(sentence[tmp_n2] == '.' || sentence[tmp_n2] == '?' || sentence[tmp_n2] == '!')
		{
			break;
		}
		if(sentence[tmp_n2] == ',')
		{
			tmp_n2++;
		} 
		if(sentence[tmp_n2] == ' ')
		{
			tmp_n1++;
			tmp_n2 += 1;
			lenth_w[tmp_n1] = 0;
			pl_w = 1;
			continue;
		}
		
		words[tmp_n1][pl_w] = sentence[tmp_n2];
		pl_w++;
		tmp_n2++;
		lenth_w[tmp_n1] ++;
	}
	
	
	int min=127;
	int num_min = 0;
	pl_w = 1;
	for(int i=1;i<=tmp_n1;i++)
	{
		for(int j=1;j<=tmp_n1;j++)
		{
			if(words[j][1] == 127)
			{
				continue;
			}
			if(words[j][pl_w] == min) 
			{
			
				pl_w++;
			
				j--;
				num_min = j;
				
				min = words[j][pl_w];
				
				continue;
			}
			if(words[j][pl_w] < min)
			{
				min = words[j][1];
			
				num_min = j;
			}
		
			pl_w = 1;
		}
		
		for(int j=1;j<=lenth_w[num_min];j++)
		{
			printf("%c",words[num_min][j]);
		} 
		printf("\n");
		min = 127;
		words[num_min][1]=127;
		num_min = 0;
	} 
	
	return 0;
} 
